package com.urerp.web.common;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.urerp.web.persistence.MenuMapper;

@Component
public class MenuUtil {
	
	@Autowired
	private MenuMapper menuMapper;
	
	public void setMenu() {
		// menu setting
        String auth_level = SessionUtil.getMemberSession("AUTH_LEVEL");
        
        if (CommonUtil.isNotEmpty(auth_level)) {
        	
        	HashMap<String, String> menuMap = new HashMap<String, String>();
        	menuMap.put("auth_level", auth_level);
        	
        	// 사이드 1 Depth 메뉴 리스트
        	menuMap.put("layout", "S");
        	menuMap.put("level", "1");
        	
        	ArrayList<LinkedHashMap<String, String>> menuList = menuMapper.getMenuList(menuMap);
        	SessionUtil.setSession("sideMenuList_1Level", menuList);
        	// request.setAttribute("sideMenuList_1Level", menuList);
        	
        	// 사이드 2 Depth 메뉴 리스트
        	menuMap.put("level", "2");
        	
        	menuList = menuMapper.getMenuList(menuMap);
        	SessionUtil.setSession("sideMenuList_2Level", menuList);
        	/*request.setAttribute("sideMenuList_2Level", menuList);*/
        	
        	// 탑 1 Depth 메뉴 리스트
        	menuMap.put("layout", "T");
        	menuMap.put("level", "1");
        	
        	menuList = menuMapper.getMenuList(menuMap);
        	SessionUtil.setSession("topMenuList_1Level", menuList);
        	/*request.setAttribute("topMenuList_1Level", menuList);*/
        	
        	// 탑 2 Depth 메뉴 리스트
        	menuMap.put("level", "2");
        	menuList = menuMapper.getMenuList(menuMap);
        	SessionUtil.setSession("topMenuList_2Level", menuList);
        	/*request.setAttribute("topMenuList_2Level", menuList);*/
        }
	}
}
